package com.work.music.dao;

import com.work.music.entity.Image;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

@Repository
public interface ImageMapper {
    @Delete({
        "delete from music_image",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String id);

    @Insert({
        "insert into music_image (id, type, ",
        "type_id, imgurl, ",
        "addtime, addip)",
        "values (#{id,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER}, ",
        "#{typeId,jdbcType=VARCHAR}, #{imgurl,jdbcType=VARCHAR}, ",
        "#{addtime,jdbcType=TIMESTAMP}, #{addip,jdbcType=VARCHAR})"
    })
    int insert(Image record);

    @Select({
        "select",
        "id, type, type_id, imgurl, addtime, addip",
        "from music_image",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="type", property="type", jdbcType=JdbcType.INTEGER),
        @Result(column="type_id", property="typeId", jdbcType=JdbcType.VARCHAR),
        @Result(column="imgurl", property="imgurl", jdbcType=JdbcType.VARCHAR),
        @Result(column="addtime", property="addtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="addip", property="addip", jdbcType=JdbcType.VARCHAR)
    })
    Image selectByPrimaryKey(String id);

    @Select({
        "select",
        "id, type, type_id, imgurl, addtime, addip",
        "from music_image"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="type", property="type", jdbcType=JdbcType.INTEGER),
        @Result(column="type_id", property="typeId", jdbcType=JdbcType.VARCHAR),
        @Result(column="imgurl", property="imgurl", jdbcType=JdbcType.VARCHAR),
        @Result(column="addtime", property="addtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="addip", property="addip", jdbcType=JdbcType.VARCHAR)
    })
    List<Image> selectAll();

    @Update({
        "update music_image",
        "set type = #{type,jdbcType=INTEGER},",
          "type_id = #{typeId,jdbcType=VARCHAR},",
          "imgurl = #{imgurl,jdbcType=VARCHAR},",
          "addtime = #{addtime,jdbcType=TIMESTAMP},",
          "addip = #{addip,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(Image record);
}